/*
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <rom.prevot@gmail.com> wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return R. Prevot
 * ----------------------------------------------------------------------------
 */

/******************************************************************************\
 *          ____                _______    _____ _             _              *
 *         |  _ \              |__   __|  / ____| |           | |             *
 *         | |_) | ___  _ __ _ __ | | ___| (___ | |_ ___   ___| | __          *
 *         |  _ < / _ \| '__| '_ \| |/ _ \\___ \| __/ _ \ / __| |/ /          *
 *         | |_) | (_) | |  | | | | | (_) |___) | || (_) | (__|   <           *
 *         |____/ \___/|_|  |_| |_|_|\___/_____/ \__\___/ \___|_|\_\          *
 *                                                                            *
\******************************************************************************/

package app.models;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author Ghost
 */
@Entity
@Table(name = "references", catalog = "BornToStock", schema = "")
@NamedQueries({
    @NamedQuery(name = "Reference.findAll", query = "SELECT r FROM Reference r"),
    @NamedQuery(name = "Reference.findById", query = "SELECT r FROM Reference r WHERE r.id = :id"),
    @NamedQuery(name = "Reference.findByDesignation", query = "SELECT r FROM Reference r WHERE r.designation = :designation"),
    @NamedQuery(name = "Reference.findByPxVenteTTC", query = "SELECT r FROM Reference r WHERE r.pxVenteTTC = :pxVenteTTC"),
    @NamedQuery(name = "Reference.findByPxAchatHT", query = "SELECT r FROM Reference r WHERE r.pxAchatHT = :pxAchatHT"),
    @NamedQuery(name = "Reference.findByVendu", query = "SELECT r FROM Reference r WHERE r.vendu = :vendu"),
    @NamedQuery(name = "Reference.findByStock", query = "SELECT r FROM Reference r WHERE r.stock = :stock"),
    @NamedQuery(name = "Reference.findByDisponible", query = "SELECT r FROM Reference r WHERE r.disponible = :disponible")})
public class Reference implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    private Integer id;
    @Basic(optional = false)
    @Column(name = "designation", nullable = false, length = 200)
    private String designation;
    @Basic(optional = false)
    @Column(name = "pxVenteTTC", nullable = false)
    private double pxVenteTTC;
    @Basic(optional = false)
    @Column(name = "pxAchatHT", nullable = false)
    private double pxAchatHT;
    @Basic(optional = false)
    @Column(name = "vendu", nullable = false)
    private int vendu;
    @Basic(optional = false)
    @Column(name = "stock", nullable = false)
    private int stock;
    @Basic(optional = false)
    @Column(name = "disponible", nullable = false)
    private boolean disponible;
    @JoinColumn(name = "categorie_id", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
    private Categorie categorie;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "reference", fetch = FetchType.EAGER)
    private List<Lignevente> ligneventeList;
    @Embedded
    private Photo photo;

    public Reference() {
    }

    public Reference(Integer id) {
        this.id = id;
    }

    public Reference(Integer id, String designation, double pxVenteTTC, double pxAchatHT, int vendu, int stock, boolean disponible) {
        this.id = id;
        this.designation = designation;
        this.pxVenteTTC = pxVenteTTC;
        this.pxAchatHT = pxAchatHT;
        this.vendu = vendu;
        this.stock = stock;
        this.disponible = disponible;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
    }

    public String getDesignation() {
        return designation;
    }

    public void setDesignation(String designation) {
        String oldDesignation = this.designation;
        this.designation = designation;
    }

    public double getPxVenteTTC() {
        return pxVenteTTC;
    }

    public void setPxVenteTTC(double pxVenteTTC) {
        double oldPxVenteTTC = this.pxVenteTTC;
        this.pxVenteTTC = pxVenteTTC;
    }

    public double getPxAchatHT() {
        return pxAchatHT;
    }

    public void setPxAchatHT(double pxAchatHT) {
        double oldPxAchatHT = this.pxAchatHT;
        this.pxAchatHT = pxAchatHT;
    }

    public int getVendu() {
        return vendu;
    }

    public void setVendu(int vendu) {
        int oldVendu = this.vendu;
        this.vendu = vendu;
    }

    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        int oldStock = this.stock;
        this.stock = stock;
    }

    public boolean getDisponible() {
        return disponible;
    }

    public void setDisponible(boolean disponible) {
        boolean oldDisponible = this.disponible;
        this.disponible = disponible;
    }

    public Categorie getCategorie() {
        return categorie;
    }

    public void setCategorie(Categorie categorie) {
        Categorie oldCategorie = this.categorie;
        this.categorie = categorie;

    }

    public List<Lignevente> getLigneventeList() {
        return ligneventeList;
    }

    public void setLigneventeList(List<Lignevente> ligneventeList) {
        this.ligneventeList = ligneventeList;
    }

    public Photo getPhoto() {
        return photo;
    }

    public void setPhoto(Photo photo) {
        this.photo = photo;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Reference other = (Reference) obj;
        if ((this.designation == null) ? (other.designation != null) : !this.designation.equals(other.designation)) {
            return false;
        }
        if (Double.doubleToLongBits(this.pxVenteTTC) != Double.doubleToLongBits(other.pxVenteTTC)) {
            return false;
        }
        if (Double.doubleToLongBits(this.pxAchatHT) != Double.doubleToLongBits(other.pxAchatHT)) {
            return false;
        }
        if (this.categorie != other.categorie && (this.categorie == null || !this.categorie.equals(other.categorie))) {
            return false;
        }
        if (this.photo != other.photo && (this.photo == null || !this.photo.equals(other.photo))) {
            return false;
        }
        return true;
    }

   

    @Override
    public String toString() {
        return "Reference[id=" + id + "; categorie=" + categorie + "]";
    }
}
